<!--

    Copyright © 2016-2025 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<mat-toolbar color="primary">
  <h2>{{ dialogTitle | translate }}</h2>
  <span class="flex-1"></span>
  <div tb-help="templateNotifications"></div>
  <button mat-icon-button
          (click)="cancel()"
          type="button">
    <mat-icon class="material-icons">close</mat-icon>
  </button>
</mat-toolbar>
<mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async">
</mat-progress-bar>
<div mat-dialog-content>
  <mat-horizontal-stepper linear #notificationTemplateStepper
                          labelPosition="end"
                          [orientation]="(stepperOrientation | async)"
                          (selectionChange)="changeStep($event)">
    <ng-template matStepperIcon="edit">
      <mat-icon>check</mat-icon>
    </ng-template>
    <mat-step [stepControl]="templateNotificationForm">
      <ng-template matStepLabel>{{ 'notification.setup' | translate }}</ng-template>
      <form [formGroup]="templateNotificationForm" style="padding-bottom: 16px;">
        <mat-form-field class="mat-block">
          <mat-label translate>notification.name</mat-label>
          <input matInput formControlName="name" required>
          <mat-error *ngIf="templateNotificationForm.get('name').hasError('required')">
            {{ 'notification.name-required' | translate }}
          </mat-error>
        </mat-form-field>
        <mat-form-field class="mat-block flex-1" *ngIf="!hideSelectType">
          <mat-label translate>notification.type</mat-label>
          <mat-select formControlName="notificationType">
            <mat-option *ngFor="let notificationType of notificationTypes" [value]="notificationType">
              {{ notificationTemplateTypeTranslateMap.get(notificationType).name | translate }}
            </mat-option>
          </mat-select>
        </mat-form-field>
        <section formGroupName="configuration">
          <label [class.tb-error]="templateNotificationForm.get('configuration.deliveryMethodsTemplates').hasError('atLeastOne')"
            class="tb-title tb-required">{{ "notification.delivery-methods" | translate }}</label>
          <div class="tb-hint" translate>notification.at-least-one-should-be-selected</div>
          <section formGroupName="deliveryMethodsTemplates" class="delivery-methods-container">
            <section *ngFor="let deliveryMethods of notificationDeliveryMethods"
                     class="tb-form-panel stroked"
                     [formGroupName]="deliveryMethods">
              <mat-slide-toggle formControlName="enabled">
                {{ notificationDeliveryMethodInfoMap.get(deliveryMethods).name | translate }}
              </mat-slide-toggle>
            </section>
          </section>
        </section>
      </form>
    </mat-step>
    <mat-step [stepControl]="notificationTemplateConfigurationForm" #composeStep=matStep>
      <ng-template matStepLabel>{{ 'notification.compose' | translate }}</ng-template>
      <ng-template matStepContent>
        <form [formGroup]="notificationTemplateConfigurationForm">
          <tb-template-configuration
            [notificationType]="templateNotificationForm.get('notificationType').value"
            [predefinedDeliveryMethodsTemplate]="deliveryConfiguration"
            [interacted]="composeStep.interacted"
            formControlName="deliveryMethodsTemplates">
          </tb-template-configuration>
        </form>
      </ng-template>
    </mat-step>
  </mat-horizontal-stepper>
</div>
<mat-divider></mat-divider>
<div mat-dialog-actions class="tb-dialog-actions">
  <button mat-stroked-button *ngIf="selectedIndex > 0"
          (click)="backStep()">{{ 'action.back' | translate }}</button>
  <span class="flex-1"></span>
  <button mat-raised-button
          color="primary"
          (click)="nextStep()">{{ nextStepLabel() | translate }}</button>
</div>
